<?php
/**
 * Copyright 2013 Marek Kaszewski
 *
 * This file is part of the JHUB1 Online Community Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

namespace Jhub1_Common\Model;

use Zend\Mime\Part as MimePart;
use Zend\Mime\Message as MimeMessage;
use Zend\Mail\Transport\Smtp;
use Zend\Mail;

/**
* @var $userPO Application\Entity\Users
 */
class Mailer
{

    public function sendPasswordReminder($userPO)
    {
        error_log("PasswordReminder Email Has been successfully sent: " . $userPO->getEmail(), 3, "/tmp/JHUB1Online-errors.log");
     //   return true;
        return false;
    }

    public function sendActivationCode($userPO)
    {
        error_log("ActivationCode Email Has been successfully sent: " . $userPO->getEmail() , 3, "/tmp/JHUB1Online-errors.log");
      // return true;
       return false;
    }

    public function sentEmail()
    {
        // setup SMTP options
        $options = new Mail\Transport\SmtpOptions(array(
            'name' => 'localhost',
            'host' => 'smtp.gmail.com',
            'port' => 587,
            'connection_class' => 'login',
            'connection_config' => array(
                'username' => 'marek.kaszewski@gmail.com',
                'password' => 'lksbubilgmail',
                'ssl' => 'tls',
            ),
        ));

        $renderer = $this->getServiceLocator()->get('ViewRenderer');
        $content = $renderer->render('mail/activate', null);

        // make a header as html
        $html = new MimePart($content);
        $html->type = "text/html";
        $body = new MimeMessage();
        $body->setParts(array($html,));

        // instance mail
        $mail = new Mail\Message();
        $mail->setBody($body); // will generate our code html from template.phtml
        $mail->setFrom('marek.kaszewski@gmail.com', 'Sender Name');
        $mail->setTo('marek.kaszewski@gmail.com');
        $mail->setSubject('Your Subject');

        $transport = new Mail\Transport\Smtp($options);
        $transport->send($mail);
    }



    /*                    $message = new \Zend\Mail\Message();
                        $message->addFrom("matthew@zend.com", "Matthew Weier O'Phinney")
                            ->addTo("marek.kaszewski@gmail.com")
                            ->setSubject("Sending an email from ZendMail!");
                        $message->setBody("This is the message body.");


                        $smtpOptions = new \Zend\Mail\Transport\SmtpOptions();

                        $smtpOptions->setHost('smtp.gmail.com')
                            ->setConnectionClass('login')
                            ->setName('smtp.gmail.com')
                            ->setPort(465)
                            ->setConnectionConfig(array(
                                'username' => 'marek.kaszewski@gmail.com',
                                'password' => 'lksbubilgmail',
                                'ssl' => 'tls',
                            ));

                        $transport = new \Zend\Mail\Transport\Smtp($smtpOptions);
                        $transport->send($message);*/
    /*
                        $mail = new Mail();
                        $config = array(
                            'host' => 'smtp.gmail.com',
                            'port' => 587,
                            'ssl' => 'tls',
                            'auth' => 'login',
                            'username' => 'marek.kaszewski@gmail.com',
                            'password' => 'lksbubilgmail',
                        );

                        $transport = new Smtp('smtp.gmail.com', $config);
                        $message = "adsdasdsds";
                        $sendNow   = $mail->setBodyHtml($message)
                            ->setFrom('marek.kaszewski@gmail.com', 'Biswa Upreti')
                            ->addTo('marek.kaszewski@gmail.com')
                            ->setSubject("test")
                            ->send($transport);*/
}